package cn.maszy.action.financialManagement;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import net.sourceforge.stripes.action.SessionScope;
import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.model.financialManagement.B_T_Ufp_Financial;
import cn.maszy.service.financialManagement.B_T_Ufp_FinancialService;

@SessionScope
public class FinancialAction extends BaseAction<B_T_Ufp_Financial> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4984910117244083916L;
	BigDecimal amountSum = new BigDecimal(0);
	BigDecimal balanceSum = new BigDecimal(0);
	private List<B_T_Ufp_Financial> list_B_T_Ufp_Financial;
	private String checkIds;
	private String strattime;
	private String endtime;
	private String flag;
	private B_T_Ufp_Financial b_T_Ufp_Financial;
	@Autowired
	private B_T_Ufp_FinancialService b_T_Ufp_FinancialService;
	
	/*********************class set/get****************************/
	public String getCheckIds() {
		return checkIds;
	}
	public void setCheckIds(String checkIds) {
		this.checkIds = checkIds;
	}
	public BigDecimal getAmountSum() {
		return amountSum;
	}
	public void setAmountSum(BigDecimal amountSum) {
		this.amountSum = amountSum;
	}
	public BigDecimal getBalanceSum() {
		return balanceSum;
	}
	public void setBalanceSum(BigDecimal balanceSum) {
		this.balanceSum = balanceSum;
	}
	public List<B_T_Ufp_Financial> getList_B_T_Ufp_Financial() {
		return list_B_T_Ufp_Financial;
	}
	public void setList_B_T_Ufp_Financial(
			List<B_T_Ufp_Financial> list_B_T_Ufp_Financial) {
		this.list_B_T_Ufp_Financial = list_B_T_Ufp_Financial;
	}
	public String getStrattime() {
		return strattime;
	}
	public void setStrattime(String strattime) {
		this.strattime = strattime;
	}
	public String getEndtime() {
		return endtime;
	}
	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	public B_T_Ufp_Financial getB_T_Ufp_Financial() {
		return b_T_Ufp_Financial;
	}
	public void setB_T_Ufp_Financial(B_T_Ufp_Financial b_T_Ufp_Financial) {
		this.b_T_Ufp_Financial = b_T_Ufp_Financial;
	}
	/*******************STRUTS ACTION METHOD*************************/
	/**
	 * 页面查询
	 * @return
	 * @throws Exception
	 */
	public String financialList() throws Exception {
		pager = new Pager<B_T_Ufp_Financial>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_FinancialService.selectList(b_T_Ufp_Financial,pager,flag,strattime,endtime);
		return SUCCESS;
	}
	/**
	 * 跳转
	 * @return
	 * @throws Exception
	 */
	public String financialJump() throws Exception {
		return SUCCESS;
	}
	/**
	 * 支出添加
	 * @return
	 * @throws Exception
	 */
	public String financialUpdate() throws Exception {
		int i	=b_T_Ufp_FinancialService.update(b_T_Ufp_Financial,flag);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "FinancialList?flag=zc", "","forward", "financialManagement/FinancialList?flag=zc");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 收入添加
	 * @return
	 * @throws Exception
	 */
	public String financialUpdate1() throws Exception {
		int i	=b_T_Ufp_FinancialService.update(b_T_Ufp_Financial,flag);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "FinancialList1?flag=sr","", "forward", "financialManagement/FinancialList1?flag=sr");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 统计查询
	 * @return
	 * @throws Exception
	 */
	public String financialStatistics() throws Exception{
		pager = new Pager<B_T_Ufp_Financial>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_FinancialService.selectList1(b_T_Ufp_Financial,pager,strattime,endtime,list_B_T_Ufp_Financial);
		for(int i=0;i<pager.getPageRecords().size();i++){
			if(pager.getPageRecords().get(i) != null){
				if(pager.getPageRecords().get(i).getSum() != null){
					amountSum = amountSum.add(new BigDecimal(pager.getPageRecords().get(i).getSum()));
				}
				if(pager.getPageRecords().get(i).getSumgod() != null){
					balanceSum = balanceSum.add(new BigDecimal(pager.getPageRecords().get(i).getSumgod()));
				}
			}
		}
		return SUCCESS;
	}
	/**
	 * 删除一条数据
	 * @return
	 * @throws Exception
	 */
	public String financialDel() throws Exception {
		int i=b_T_Ufp_FinancialService.delete(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "FinancialList?flag=zc", "","forward", "financialManagement/FinancialList?flag=zc");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 删除一条数据1
	 * @return
	 * @throws Exception
	 */
	public String financialDel1() throws Exception {
		int i=b_T_Ufp_FinancialService.delete(checkIds);
		if(i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "FinancialList1?flag=sr","", "forward", "financialManagement/FinancialList1?flag=sr");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
}
